﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections.Specialized;

namespace System.Collections.Observable.DebugViews
{
    internal class ObservableDictionaryBaseDebugView<TKey, TValue, TDict> where TDict : IDictionary<TKey, TValue>
    {
        ObservableDictionaryBase<TKey, TValue, TDict> ObservableDictionary;

        [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]
        [DebuggerDisplay("{InternalCollection.Count}", Name = "Internal Dictionary")]
        public TDict InternalCollection
        {
            get
            {
                return ObservableDictionary.InternalCollection;
            }
        }

        [DebuggerDisplay("{SubscribersCount}")]        
        public NotifyCollectionChangedEventHandler Subscribers
        {
            get
            {
                return ObservableDictionary.CollectionChangedSubscribers;
            }
        }

        private int SubscribersCount
        {
            get
            {
                NotifyCollectionChangedEventHandler subscribers = ObservableDictionary.CollectionChangedSubscribers;
                if (subscribers == null)
                {
                    return 0;
                }
                else
                {
                    return subscribers.GetInvocationList().Length;
                }
            }
        }

        public ObservableDictionaryBaseDebugView(ObservableDictionaryBase<TKey, TValue, TDict> observableDict)
        {
            ObservableDictionary = observableDict;
        }
    }
    
}
